<?php

namespace app\model;

use think\Model;

class UserBalance extends Model
{
    public function balanceTotal(): array
    {
        $data = $this->where([
            "uid" => request()->param("uid")
        ])->order(['create_time' => 'desc'])->paginate(['list_row' => 30, 'page' => request()->param('page')])->toArray();

        return ['lst' => array_map(function ($item) {
            $item['number'] = (float)bcdiv($item['number'], 100, 2);
            return $item;
        }, $data['data']), 'last_page' => $data['last_page']];
    }

    public function balanceCht(): float
    {
        $data = $this->where(['uid' => request()->param('uid'), 'type' => 4])->sum('number');
        return $data > 0 ? (float)bcdiv($data, 100, 2) : 0;
    }
}
